package com.ad.admin.androidadapt;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class MainActivity extends AppCompatActivity {
    private List<Map<String,Object>> lst;
    private ListView lv;
    public void init(){
        lst = new ArrayList<Map<String,Object>>();
        Map<String,Object> m1 = new HashMap<String, Object>();
        Map<String,Object> m2 = new HashMap<String, Object>();
        Map<String,Object> m3 = new HashMap<String, Object>();

        m1.put("image",R.drawable.a);
        m1.put("title","t1");
        m1.put("content","dsfjklcs");

        m2.put("image",R.drawable.b);
        m2.put("title","t2");
        m2.put("content","dsfdsrsewe232");

        m3.put("image",R.drawable.c);
        m3.put("title","t3");
        m3.put("content", "dsf23214klcs");

        lst.add(m1);lst.add(m2);lst.add(m3);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        init();
        lv = (ListView)findViewById(R.id.lv);
        ListAdapter adapter = new SimpleAdapter(this,lst,R.layout.news_layout,new String[]{"image","title","content"},
                new int[]{R.id.image,R.id.title,R.id.content}
                );
        lv.setAdapter(adapter);

    }
}
